package com.yyc.system.controller;
import com.yyc.core.Result;
import com.yyc.core.ResultGenerator;
import com.yyc.system.model.TCollege;
import com.yyc.system.service.ITCollegeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* Created by yyc on 2019/01/13.
*/
@RestController
@RequestMapping("/t/college")
public class TCollegeController {
    @Autowired
    private ITCollegeService tCollegeService;

    @RequestMapping("/add")
    public Result add(@RequestBody TCollege tCollege) {
        tCollegeService.save(tCollege);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        tCollegeService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody TCollege tCollege) {
        tCollegeService.update(tCollege);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TCollege tCollege = tCollegeService.findById(id);
        return ResultGenerator.genSuccessResult(tCollege);
    }

    @RequestMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<TCollege> list = tCollegeService.findAll();
        PageInfo<TCollege> pageInfo = new PageInfo<TCollege>(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
